﻿using NWNT.Web.Constants;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Web;

namespace NWNT.Web.Models
{
    [DataContract]
    public class QuestionAreaModel: IValidatableObject
    {
        [DataMember]
        public int QuestionAreaId { get; set; }

        //[Required(ErrorMessage = ValidationMessages.MasterMessages.QuestionAreaNameEmpty, AllowEmptyStrings = false)]
        [DataMember]
        public string Area { get; set; }
        
        //[Required(ErrorMessage = ValidationMessages.MasterMessages.QuestionAreaDescriptionEmpty)]
        [DataMember]
        public string Description { get; set; }

        [DataMember]
        public int Order { get; set; }

        [DataMember]
        public IEnumerable<QuestionOptionsModel> QuestionOptions { get; set; }

        [DataMember]
        public IEnumerable<int> SelectedQuestionOptions { get; set; }

        [DataMember]
        public IEnumerable<int> SelectedQuestionOptionsScores { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            string errors = string.Empty;
            if (string.IsNullOrEmpty(Area))
            {
                errors = ValidationMessages.MasterMessages.QuestionAreaNameEmpty;
            }

            if (string.IsNullOrEmpty(Description))
            {
                errors = errors + (string.IsNullOrEmpty(errors) ? "" : "<br />");
                errors = errors + ValidationMessages.MasterMessages.QuestionAreaDescriptionEmpty;
            }

            if (SelectedQuestionOptions == null || SelectedQuestionOptions.Count() == 0)
            {
                errors = errors + (string.IsNullOrEmpty(errors) ? "" : "<br />");
                errors = errors + ValidationMessages.MasterMessages.QuestionAreaQuestionEmpty;
            }

            if (!string.IsNullOrEmpty(errors))
            {
                yield return
                    new ValidationResult(errors);
            }
        }
    }
}